cd "/Users/dawnshen/Dropbox/Yinzhi/MassShootings/MassShootingsData/ViolenceProject"
****************************
****************************
** ViolenceProject city
****************************
****************************

use "ViolenceProject_city_working_analysisfile", clear
*************************************************************************	
* Generate indicators of interview timing 
*************************************************************************	
drop if date==msdate //Drop obs if being interviewed on the MS day

gen bf28=0
replace bf28=1 if date-msdate>=-28 & date-msdate<=-1 //interviewed in the four weeks before the incident - control group
gen r_af1=0 //interviewed one day after the incident
replace r_af1=1 if date-msdate==1
gen bf28_1=0
replace bf28_1=1 if r_af1==1 | bf28==1  //interviewed one day after the incident or in the control group

foreach i in 2 4 7 14 21 28 {
gen r_af`i'=0
replace r_af`i'=1 if date-msdate>=`i'-1 & date-msdate<=`i'+1  //interviewed around i days after the incident

gen bf28_`i'=0
replace bf28_`i'=1 if bf28==1 | r_af`i'==1 //interviewed around i days after the incident or in the control group
replace bf28_`i'=. if date-msdate>0 & date-msdate<`i'-1 //remove those interviewed after MS and before i-1 days from the model
}

* # of respondents interviewed on the (i-1)th - (i+1)th day since MS
foreach i in 1 2 4 7 14 21 28 {
tab1 r_af`i', m
}


*************************************************************************
* SI Figure S4 The effect of mass shootings on daily emotions: three day average effect
*************************************************************************		
local rownames ""
mata: estimates = J(0,3,.)
foreach i in sadness anger happy smile {
  foreach j in 1 2 4 7 14 21 28 {  
	        quietly xtreg `i' r_af`j' bf28_`j' rwhite coll married female age i.kids i.year i.month i.dow, fe i(cityid) level(90) 
            mata: estimates = estimates \ st_matrix("r(table)")'[1, (1,5,6)]
            local rownames `rownames' `i'_`j'
    }
	}
mata: st_matrix("emotion", estimates)
matrix rownames emotion = `rownames'
matrix colnames emotion = Coef LL UL
matprint emotion, d(3)

coefplot (matrix(emotion[,1]), ci((emotion[,2] emotion[,3])) msize(small) mcolor(black)), yline(0,lcolor(grey) lpattern(dash) lwidth(.3)) graphregion(color(white)) vertical ytitle("Effect size",size(small)) ylabel(-.5(0.1).5, labsize(vsmall) angle(horizontal)) groups(sadness_* = Sadness anger_* = Anger happy_* = Happy smile_* = Smile) yscale(range(-.5(0.1).5)) xlabel(1 "day1" 2 "day2" 3 "day4" 4 "day7" 5 "day14" 6 "day21" 7 "day28" 9 "day1" 10 "day2" 11 "day4" 12 "day7" 13 "day14" 14 "day21" 15 "day28" 17 "day1" 18 "day2" 19 "day4" 20 "day7" 21 "day14" 22 "day21" 23 "day28" 25 "day1" 26 "day2" 27 "day4" 28 "day7" 29 "day14" 30 "day21" 31 "day28", labsize(vsmall) angle(vertical) )  
graph export Violence_citybfaf_3day_controls_byemotion.pdf, replace
